package com.pearlsoft.webapp.core.dataset;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * 
 * DataSet
 * 
 * @Creator haitingr
 * @Create-DateTime 2011-10-24
 */
public interface DataSet {

	public static final String _name_attribute = "name";

	public static final String _record_attriubte = "record";

	public static final String _condition_attribute = "condition";
	
	public static final String _condition_fieldName = "fieldName";
	public static final String _condition_value = "value";


	public static final String _handler_attribute = "handler";
	
	public static final String _method_attribute="handlerMethod";

	public static final String _page_attribute = "page";

	public static final String _field_attribute = "field";
	
	public static final String _sucess_attribute="success";

	/**
	 * 
	 * @return
	 */
	String getName();

	/**
	 * 
	 * @param name
	 * @return
	 */
	Field getField(String name);

	/**
	 * 
	 * @param fields
	 */
	void setFields(List<Field> fields);

	/**
	 * record index will move next,if has no record,return false
	 */
	boolean next();

	/**
	 * 
	 */
	void reset();

	/**
	 * 
	 */
	void first();

	/**
	 * 
	 */
	void last();

	/**
	 * 
	 * @return
	 */
	int size();

	/**
	 * 
	 * @param name
	 * @param value
	 * @throws DataSetFieldNotExistException
	 */
	void addCondition(String name, Object value) throws DataSetFieldNotExistException;

	/**
	 * 
	 * @return
	 */
	Map<String, Object> getConditions();

	/**
	 * 
	 * @return
	 */
	boolean newRecord();

	/**
	 * 
	 * @param fieldName
	 * @return
	 */
	Object getValue(String fieldName) ;

	/**
	 * 
	 * @param fieldName
	 * @param value
	 */
	void setValue(String fieldName, Object value);

	/**
	 * 
	 * @return
	 */
	byte[] toJson() throws IOException, DataSetException;

	// page support

	int getPageSize();

	void setPageSize(int pageSize);

	int getTotalCount();

	int getEndIndex();

	void setTotalCount(int totalCount);


	int getStartIndex();

	void setStartIndex(int startIndex);

	int getNextIndex();

	int getPreviousIndex();

	int getPageIndex();

	int getPageCount();
	List<Record> getRecords();
	void setRecords(List<Record> records);
	void addRecrod(Record record);
	Record getCurrentRecord();

}
